<template>
	<view class="page">
		<image src="../../static/register/top2.jpg" mode="widthFix" class="top" />
		<view class="location-container">
			<view class="left">
				<image src="../../static/register/location.png" mode="widthFix" class="location"></image>
				<text>代驾服务地点</text>
			</view>
			<view class="right">{{ cityName }}</view>
		</view>
		<view class="info-container">
			<view class="title-container">
				<image src="../../static/register/title-bg.png" mode="widthFix" class="title-bg"></image>
				<text class="title">注册条件</text>
			</view>
			<view class="list">
				<view class="item">
					<text>1.</text>
					车辆合规合法；
				</view>
				<view class="item">
					<text>2.</text>
					年龄18岁以上；
				</view>
				<view class="item">
					<text>3.</text>
					无违法犯罪记录、无精神病史、无吸毒史，以及平台认为不适合使用代驾的其他历史证明；
				</view>


			</view>
		</view>
		<view class="info-container">
			<view class="title-container">
				<image src="../../static/register/title-bg.png" mode="widthFix" class="title-bg"></image>
				<text class="title">使用流程</text>
			</view>
			<view class="list">
				<view class="complex-item">
					<view class="left">01</view>
					<view class="right">
						<text class="item-title">在线注册账号</text>
						<text class="item-desc">在小程序完成注册</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">02</view>
					<view class="right">
						<text class="item-title">个人信息填写</text>
						<text class="item-desc">按照流程提交本人身份证照片</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">03</view>
					<view class="right">
						<text class="item-title">代驾下单</text>
						<text class="item-desc">通过APP下单预约代驾</text>
					</view>
				</view>
				<view class="complex-item">
					<view class="left">04</view>
					<view class="right">
						<text class="item-title">费用支付</text>
						<text class="item-desc">订单结束自动扣除费用</text>
					</view>
				</view>
			</view>
		</view>
		<button class="btn" @tap="wxRegister">乘客注册</button>
		<!-- <button class="btn" open-type="getPhoneNumber" @getphonenumber="phoneRegister" >微信注册</button> -->
		<u-toast ref="uToast" />
	</view>
</template>

<script>
	var QQMapWX = require('../../lib/qqmap-wx-jssdk.min.js');
	var qqmapsdk;
	export default {
		data() {
			return {
				code: null,
				cityName: "日本"
			};
		},
		onLoad() {
			let _this = this;
			_this.init();
			_this.reverseGeocoder();
		},
		methods: {
			//初始化参数
			init() {
				qqmapsdk = new QQMapWX({
					key: 'DVQBZ-3UM64-4LLU4-F2ATG-CW6R2-LFBOG' // 必填
				});
			},
			//通过uniapp获取当前位置的经纬度
			getLocation() {
				uni.getLocation({
					type: 'wgs84', // 返回可以用于uni.openLocation的经纬度，默认为wgs84的gps坐标
					success: (res) => {
						console.log('当前位置的经度：' + res.longitude);
						console.log('当前位置的纬度：' + res.latitude);
					},
					fail: (err) => {
						console.error('获取位置失败：', err);
					}
				});
			},
			//通过腾讯地图接口位置信息
			reverseGeocoder() {
				const _this = this;
				qqmapsdk.reverseGeocoder({
					success: (resp) => {
						_this.cityName = resp.result.address_component.city
					},
					fail: function(error) {
						uni.showToast({
							title: '获取地址失败',
							icon: 'error'
						})
					}
				})
			},
			//利用openid实现司机注册
			wxRegister() {
				const _this = this;
				uni.removeStorageSync("tokenName");
				uni.removeStorageSync("tokenValue");
				uni.removeStorageSync("permissions");
				uni.removeStorageSync("loginInfo");
				wx.login({
					success(res) {
						console.log(res)
						if (res.code) {
							_this.get('/customer/app/customer/register/' + res.code, (resp) => {
								if (resp.success) {
									uni.showToast({
										title: "注册成功",
										icon: "success"
									})
									setTimeout(() => {
										uni.navigateTo({
											url: '/pages/login/login'
										})
									}, 2000)
								} else {
									uni.showToast({
										title: resp.message,
										icon: "error"
									})
								}
							})
						} else {
							uni.showToast({
								title: "注册异常",
								icon: "error"
							})
						}
					}
				})
			},
			//利用手机号实现司机注册
			phoneRegister(e) {
				let phoneCode = e.detial.code;
				const _this = this;
				wx.login({
					success(res) {
						if (res.code) {
							_this.get('/customer/app/customer/registerByPhone/' + res.code + '/' + phoneCode, (
								resp) => {
								if (resp.success) {
									uni.showToast({
										title: "注册成功",
										icon: "success"
									})
									setTimeout(() => {
										uni.navigateTo({
											url: '/pages/login/login'
										})
									}, 2000)
								} else {
									uni.showToast({
										title: resp.message,
										icon: "error"
									})
								}
							})
						} else {
							uni.showToast({
								title: "注册异常",
								icon: "error"
							})
						}
					}
				})
			}
		}
	};
</script>

<style lang="less">
	@import url('register.less');
</style>